home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / fileBrowser.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  38.4 KB  |  1,472 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  December 9, 1996
  22. //
  23. //  Description:
  24. //      File Browser.
  25. //
  26. //  Input Arguments:
  27. //      String      Callback on OK action
  28. //        String        action name for button and window title
  29. //        String        The type of file requested.
  30. //        Int            The browser mode. 
  31. //                        0 for read.
  32. //                        1 for write. (export)
  33. //                        2 for write without paths. (file save)
  34. //                        4 directories have meaning when used with the
  35. //                            action button.
  36. //
  37. //
  38. //    Globals that may be used:
  39. //        $gDefaultFileBrowserDir    - If not "" then the file options
  40. //                                for default Dir will take you to the
  41. //                                directory specified.
  42. // 
  43. //  Return Value:
  44. //      Done through the callback provided. The callback has the following
  45. //        parameters:
  46. //            String        The file specified by the user.
  47. //            String        The type of file specified by the user.
  48. //
  49. //        If the user wishes to provide more parameters to the callback they
  50. //        may do so providing that the last two parameters are the ones given
  51. //        above.
  52. //
  53. //        The callback returns true if the window should be removed when
  54. //        done.
  55. //
  56. //        Eg.
  57. //            myCallBack myParam1 myParam2 filePath fileType
  58. //
  59.  
  60.  
  61. //
  62. //    Globals used by the browser.
  63. //
  64. global string $gv_CallBackCommand;
  65. global int $gv_displayMode;
  66. global int $gv_displayHiddenMode;
  67. global int $gv_browserMode;        // 0 for read, 1 for write.
  68.  
  69. global string $gDefaultFileBrowserDir = "";
  70.  
  71. //
  72. //    Menus.
  73. //
  74.  
  75. global proc sv_FileMenuProjects (string $parent)
  76. //
  77. //  Description:
  78. //      Build the File menu for the file browser.
  79. //        The first items of this menu are static and allow the
  80. //        user to move to specific directories quickly.  The
  81. //        second set of items are built dynamically and show
  82. //        the projects that the user has created.
  83. //
  84. //  Input Arguments:
  85. //      The parent control that menu will be created in.
  86. //
  87. //  Return Value:
  88. //      None.
  89. //
  90. {
  91.     global string $gDefaultFileBrowserDir;
  92.     global int $gv_browserMode;
  93.  
  94.     string $currentProject = `workspace -q -rd`;
  95.     if ( size( $currentProject ) > 0 )
  96.         $projectsDir = dirname( $currentProject ) + "/";
  97.     else
  98.         $projectsDir = `internalVar -uad`+"projects/";
  99.     string $scenesDir = $currentProject + `workspace -q -ote "scene"`;
  100.     string $homeDir = `getenv "HOME"`;
  101.     string $defaultDir;
  102.     if ($gDefaultFileBrowserDir != "") {
  103.         $defaultDir = $gDefaultFileBrowserDir;
  104.     } else {
  105.         $defaultDir = `workspace -q -dir`;
  106.     }
  107.     
  108.     // Rebuild the projects menu items.
  109.  
  110.     // Remove the old menu items
  111.     //
  112.     menu -e -deleteAllItems $parent;
  113.     
  114.     // Build the static items
  115.     //
  116.  
  117.     // We want to allow jumping to the project dialog from the
  118.     // file dialog - a value of 4 means that they're already in
  119.     // the project dialog (so we don't want the menu there!)
  120.     if ( $gv_browserMode != 4 )
  121.     {
  122.         menuItem -p $parent -l "Set Project"
  123.             -c "setProject \"\"";
  124.     
  125.         menuItem -p $parent -d true;
  126.     }
  127.  
  128.     menuItem -p $parent -l "Go to Current Project" 
  129.         -c "pv_goCurrentProject";
  130.  
  131.     menuItem -p $parent -l "Go to Current scenes"
  132.         -c ("pv_goDirectory \""+$scenesDir+"\"") scenesItem;
  133.  
  134.     menuItem -p $parent -l "Go to Home"
  135.         -c ("pv_goDirectory \""+$homeDir+"\"");
  136.  
  137.     menuItem -p $parent -l "Go to Projects" 
  138.         -c ("pv_goDirectory \""+$projectsDir+"\"") projectsItem;
  139.     
  140.     menuItem -p $parent -l "Go to Default"
  141.         -c ("pv_goDirectory \""+$defaultDir+"\"") defaultItem;
  142.  
  143.  
  144.     // If $dirStat == 0 then either 'stat' doesn't exist or
  145.     // failed somehow so don't try to build the dynamic items
  146.     // or we'll end up building them on every menu access which
  147.     // will be very slow.
  148.     //
  149.  
  150.     // Stick in a divider line
  151.     //
  152.     menuItem -p $parent -d true; 
  153.  
  154.     // Build the dynamic items
  155.     //
  156.  
  157.     string $listOfFiles[] = `workspace -l $projectsDir`;
  158.  
  159.     string $cmd;
  160.     string $aDir;
  161.     string $testDir;
  162.     string $fileType[];
  163.  
  164.     for ($aDir in $listOfFiles) {
  165.         $testDir = $projectsDir+$aDir;
  166.  
  167.         $fileType = `file -q -type $testDir`;
  168.  
  169.         if (size($fileType) > 0 && "directory" == $fileType[0]) {
  170.             $cmd = "pv_goDirectory \""+$testDir+"\"";
  171.             menuItem -p $parent -l $aDir -c $cmd;
  172.         }
  173.     }
  174. }
  175.  
  176. global proc int sv_FileMenu (string $parent)
  177. //
  178. //  Description:
  179. //      This is the popup menu for the project file viewer pane.
  180. //
  181. {    
  182.     menu -p $parent -l "File" 
  183.         -pmc "sv_FileMenuProjects \"projectViewerFileMenu\""
  184.         projectViewerFileMenu;
  185.  
  186.     return 1;
  187. }
  188.  
  189. proc int sv_ViewMenu ( string $parent )
  190. {
  191.     global int $gv_displayHiddenMode;
  192.  
  193.     // The View Menu.
  194.     menu -p $parent -l "View" viewMenu;
  195.         radioMenuItemCollection viewerMenuCluster;
  196.         menuItem -l "as Text" -rb false -c ("pv_setDisplayMode 10") textListItem;
  197.         menuItem -l "as Icons" -rb false -c ("pv_setDisplayMode 0") iconListItem;
  198. //        menuItem -l "as Small Icons" -rb false -c ("pv_setDisplayMode 1") smallIconListItem;
  199. //        menuItem -l "as References" -rb false -c ("pv_setDisplayMode 2") referencedListItem;
  200.  
  201.         setParent -m viewMenu;
  202.         menuItem -d true;
  203.         menuItem
  204.             -l "Display Hidden Files"
  205.             -cb $gv_displayHiddenMode
  206.             -c ("pv_setDisplayHiddenMode") displayHiddenItem;
  207.  
  208.     return 1;
  209. }
  210.  
  211. proc int sv_SortMenu ( string $parent )
  212. {
  213.     string $sortByMode;
  214.  
  215.     if (!`optionVar -ex fileBrowserSortMode`) {
  216.         optionVar -sv fileBrowserSortMode "name";
  217.     }
  218.     $sortByMode = `optionVar -q fileBrowserSortMode`;
  219.  
  220.     // The Sort Menu.
  221.     menu -p $parent -l "Sort" sortMenu;
  222.         radioMenuItemCollection sortMenuCluster;
  223.         menuItem -l "by Name" -rb true -c ("pv_setSortMode name") sortByNameItem;
  224.         menuItem -l "by Date" -rb false -c ("pv_setSortMode date") sortByDateItem;
  225.         menuItem -l "by Size" -rb false -c ("pv_setSortMode size") sortBySizeItem;
  226.  
  227.     switch ($sortByMode) {
  228.     case "date":
  229.         menuItem -e -rb on ($parent+"|sortMenu|sortByDateItem");
  230.         break;
  231.     case "size":
  232.         menuItem -e -rb on ($parent+"|sortMenu|sortBySizeItem");
  233.         break;
  234.     default:
  235.         // Do nothing as name is already selected.
  236.         //
  237.         break;
  238.     }
  239.     return 1;
  240. }
  241.  
  242. global proc buildFileContextHelpItems(string $nameRoot, string $menuParent)
  243. //
  244. //  Description:
  245. //        Build context sensitive menu items for this window.  
  246. //        
  247. //  Input Arguments:
  248. //        $nameRoot - name to use as the root of all item names
  249. //        $menuParent - the name of the parent of this menu
  250. //
  251. //  Return Value:
  252. //      None
  253. //
  254. {
  255.     menuItem -label "Help on File Browser..."
  256.         -enableCommandRepeat false
  257.         -command "showHelp FileBrowser";
  258. }
  259.  
  260. global proc int sv_Menu ( string $windowName )
  261. //
  262. //    Description:
  263. //        Create the menus 
  264. //
  265. {
  266.     sv_FileMenu $windowName;
  267.     sv_ViewMenu $windowName;
  268.     sv_SortMenu $windowName;
  269.  
  270.     // One more menu to bring up the option box
  271.     //
  272.     menu -p $windowName -l "Options" fileOptionsMenu;
  273.         menuItem fileOptionsMenuItem;
  274.  
  275.     //    Add support for the Context Sensitive Help Menu.
  276.     //
  277.     addContextHelpProc $windowName "buildFileContextHelpItems";
  278.     doHelpMenu($windowName, $windowName);
  279.  
  280.     return 1;
  281. }
  282.  
  283.  
  284. // Callback procs.
  285. //
  286.  
  287.  
  288. global proc pv_redrawView ( ) 
  289. //
  290. //    Description:
  291. //        redraw the view of the current workspace for the top
  292. //        viewing tab.
  293. //
  294. {
  295.     global int $gv_displayMode;
  296.     global string $gv_wsFinder;
  297.  
  298.     string $topTabName;
  299.     int $wsIndex;
  300.  
  301.     string $workspaceList[];    // Replacing -lfw with -fn. -rams
  302.     $str = `workspace -q -fn`;
  303.     $workspaceList[0] = $str;
  304.  
  305.     string $theWorkspace;
  306.     string $wsViewerForm;
  307.     string $projectPath;
  308.     string $curPath;
  309.     
  310.     $wsViewerForm = `tabLayout -q -st workspaceTabs`;
  311.  
  312.     $wsIndex = `tabLayout -q -sti workspaceTabs`;
  313.     $wsIndex = $wsIndex - 1;    // Make it 0 based for WS index.
  314.     
  315.     $theWorkspace = $workspaceList[$wsIndex];
  316.     
  317.     workspace -u $theWorkspace;        // Update the workspace cache.
  318.     
  319.     $projectPath = `workspace -q -dir $theWorkspace`;
  320.     $curPath = `finder -q -fp $gv_wsFinder`;
  321.     if ($curPath != $projectPath) {
  322.         // This is an expensive operation.
  323.         finder -e -fp $projectPath $gv_wsFinder;
  324.     }
  325.     
  326.     // Create the appropriate viewer if we don't already have it.
  327.     
  328.     switch ($gv_displayMode) {
  329.     case    0        :    // Large Icon View
  330.         pv_projIconViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
  331.         menuItem -e -rb true iconListItem;
  332.         break;
  333.     case    1        :    // Small Icon View
  334. //        pv_projSmallIconViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
  335. //        menuItem -e -rb true smallIconListItem;
  336. //        break;
  337.     case    2        :    // Reference View
  338. //        pv_projRefViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
  339. //        menuItem -e -rb true referencedListItem;
  340. //        break;
  341.     case    3        :    // Setup View
  342. //        menuItem -e -rb true viewWorkspaceEdit;
  343.         break;
  344.     case    10        :    // Text (default) View
  345.     default            :
  346.         menuItem -e -rb true textListItem;
  347.         pv_projTextViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
  348.         break;
  349.     }
  350.     
  351. }
  352.  
  353. global proc pv_setSortMode( string $mode )
  354. //
  355. // The user has changed the sort method.  Update the viewer.
  356. //
  357. {
  358.     string $wsViewerForm;
  359.     string $wsViewerName[2];
  360.     $wsViewerForm = `tabLayout -q -st workspaceTabs`;
  361.     $wsViewerName = `formLayout -q -ca $wsViewerForm`;
  362.  
  363.     projFileViewer -e -sortBy $mode $wsViewerName[0];
  364.  
  365.     optionVar -sv fileBrowserSortMode $mode;
  366. }
  367.  
  368.  
  369. global proc pv_setDisplayMode ( int $mode )
  370. //
  371. //    Description:
  372. //        Set the display mode to the given mode.
  373. //
  374. {
  375.     global int $gv_displayMode;
  376.     
  377.     $gv_displayMode = $mode;
  378.  
  379.     optionVar -iv fileBrowserDisplayMode $gv_displayMode;
  380.     
  381.     pv_redrawView;
  382. }
  383.  
  384.  
  385. global proc pv_setDisplayHiddenMode ( )
  386. //
  387. //    Description:
  388. //        Set or clear the flag to display hidden files.
  389. //
  390. //
  391. {
  392.     global int $gv_displayHiddenMode;
  393.     string $wsViewerForm;
  394.     string $wsViewerName[2];
  395.  
  396.     $wsViewerForm = `tabLayout -q -st workspaceTabs`;
  397.     $wsViewerName = `formLayout -q -ca $wsViewerForm`;
  398.  
  399.     int $mode = `menuItem -q -cb displayHiddenItem`;
  400.  
  401.     // projFileViewer -e -displayHidden $mode $wsViewerName[0];
  402.  
  403.     optionVar -iv fileBrowserDisplayHiddenMode $mode;
  404.     $gv_displayHiddenMode = $mode;
  405.     
  406.     pv_redrawView;
  407. }
  408.  
  409.  
  410. global proc int sv_newFileType ( )
  411. //
  412. //    Description:
  413. //        This is the callback for the file type list.
  414. //
  415. {
  416.     return 1;
  417. }
  418.  
  419.  
  420. global proc int pv_doubleClickAction ( int $filterDirs )
  421. //
  422. //    Description:
  423. //        open the selected item.
  424. //
  425. //    Parameters:
  426. //        $filterDirs        - 1 if directories should be used to navigate.
  427. //                        - 0 if directories have meaning.
  428. //
  429. {
  430.     global string $gv_CallBackCommand;
  431.     global string $gv_wsFinder;
  432.     global string $gv_operationMode;
  433.     global int $gv_browserMode;
  434.     
  435.     string $fileType;
  436.     string $thePath;
  437.     string $newPath;
  438.     int        $wsIndex;
  439.     string    $theWorkspace;
  440.     string    $workspaceList[];
  441.     int        $status;
  442.     string    $realType[];
  443.  
  444.     $thePath = `finder -q -fp $gv_wsFinder`;
  445.     
  446.     // Maybe the user has entered in some ~'s or env vars by hand-
  447.     // this expandName call expands those out (we only want to reset
  448.     // the finder if the path's really changed though)
  449.     $newPath = `file -q -expandName $thePath`;
  450.     if ( $newPath != $thePath )
  451.     {    
  452.         $thePath = $newPath;
  453.         finder -e -fp $thePath $gv_wsFinder;
  454.     }
  455.  
  456.     if ($thePath == "") {
  457.         $thePath = "/";        // Then it must be the root.
  458.         finder -e -fp $thePath $gv_wsFinder;
  459.     }
  460.  
  461.     int    $index = `optionMenu -q -select fileTypePopList`;
  462.  
  463.     string $typeList[] = `optionMenu -q -ils fileTypePopList`;
  464.     $fileType = `menuItem -q -l $typeList[$index-1]`;
  465.     if (`file -q -ex $thePath`) {
  466.         $realType = `file -q -typ $thePath`;
  467.     }
  468.  
  469.     int $renderGlobalsFileType = `getAttr defaultRenderGlobals.outf`;
  470.     int $resetRenderGlobalsFileType = true;
  471.     if ($fileType == "Best Guess") {
  472.         $resetRenderGlobalsFileType = false;
  473.  
  474.         // If Any then ask the file for its real type.
  475.         int $numTrans = size($realType);
  476.         int $index;
  477.         if ($numTrans > 0) {
  478.             for ($index = 0; $index < $numTrans; $index++) {
  479.                 switch ($gv_browserMode) {
  480.                   case    0        :    // Read mode.
  481.                   case    4        :
  482.                     if (`translator -q -rs $realType[$index]`) {
  483.                         $fileType = $realType[$index];
  484.                         $index = $numTrans;
  485.                     }
  486.                     break;
  487.                   case    1        :    // Write mode.
  488.                   case    2        :
  489.                     if (`translator -q -ws $realType[$index]`) {
  490.                         $fileType = $realType[$index];
  491.                         $index = $numTrans;
  492.                     }
  493.                     break;
  494.                 }
  495.             }
  496.         } else {
  497.             $fileType = "Best Guess";
  498.         }
  499.     } else if ($fileType == "Maya IFF (iff)") {
  500.         setAttr defaultRenderGlobals.outf 7;
  501.     } else if ($fileType == "Alias PIX (als)") {
  502.         setAttr defaultRenderGlobals.outf 6;
  503.     } else if ($fileType == "Cineon (cin)") {
  504.         setAttr defaultRenderGlobals.outf 11;
  505.     } else if ($fileType == "EPS (eps)") {
  506.         setAttr defaultRenderGlobals.outf 9;
  507.     } else if ($fileType == "GIF (gif)") {
  508.         setAttr defaultRenderGlobals.outf 0;
  509.     } else if ($fileType == "JPEG (jpg)") {
  510.         setAttr defaultRenderGlobals.outf 8;
  511.     } else if ($fileType == "Quantel (yuv)") {
  512.         setAttr defaultRenderGlobals.outf 12;
  513.     } else if ($fileType == "RLA (rla)") {
  514.         setAttr defaultRenderGlobals.outf 2;
  515.     } else if ($fileType == "SGI (sgi)") {
  516.         setAttr defaultRenderGlobals.outf 5;
  517.     } else if ($fileType == "SoftImage (pic)") {
  518.         setAttr defaultRenderGlobals.outf 1;
  519.     } else if ($fileType == "Targa (tga)") {
  520.         setAttr defaultRenderGlobals.outf 19;
  521.     } else if ($fileType == "Tiff (tif)") {
  522.         setAttr defaultRenderGlobals.outf 3;
  523.     } else if ($fileType == "Windows Bitmap (bmp)") {
  524.         setAttr defaultRenderGlobals.outf 20;
  525.     } else {
  526.         $resetRenderGlobalsFileType = false;
  527.     } 
  528.         
  529.     if ($filterDirs == 1 && size($realType) > 0 && $realType[0] == "directory") {
  530.         // Then we have a path.
  531.         $wsIndex = `tabLayout -q -sti workspaceTabs`;
  532.         $wsIndex = $wsIndex - 1;    // Make it 0 based for WS index.
  533.  
  534.         $str = `workspace -q -fn`;    // Replacing -lfw with -fn. -rams
  535.         $workspaceList[0] = $str;
  536.         $theWorkspace = $workspaceList[$wsIndex];
  537.  
  538.         workspace -dir $thePath $theWorkspace;
  539.  
  540.         // Fix the sound/image buttons
  541.         button -e -enable false pv_viewImageButton;
  542.         button -e -enable false pv_playSoundButton;
  543.         
  544.         pv_redrawView;    // refresh the view.
  545.         $status = false;
  546.     } else {
  547.         $status = eval($gv_CallBackCommand+" \""+$thePath+"\" \""+$fileType+"\"");
  548.     }
  549.  
  550.     // reset output image format.
  551.     if ($resetRenderGlobalsFileType)
  552.         setAttr defaultRenderGlobals.outf ($renderGlobalsFileType);
  553.     
  554.     if ($status) {
  555.         // The action completed successfully.
  556.         window -e -vis false projectViewerWindow;
  557.         $gv_operationMode = "";
  558.     }
  559.     
  560.     return 1;
  561. }
  562.  
  563. proc pv_setMenuFileType ( string $newType, int $setup )
  564. //
  565. //    Description:
  566. //        set the select menu type in the fileTypePopList 
  567. //        to the type given.
  568. //
  569. {
  570.     global int $gv_browserMode;
  571.     int $numTypes;
  572.     string $typeList[];
  573.     string $qFileType;
  574.     
  575.     // Show the user what the file type is
  576.     //
  577.     text -edit -l $newType fileTypeFeedback;
  578.     
  579.     if ($setup || ($gv_browserMode != 1 && $gv_browserMode != 2)) {
  580.         // Don't change the type if we are writing the file.
  581.  
  582.         // Change the popup to be the closest file type to
  583.         // what can actually be read/written
  584.         //
  585.         $numTypes = `optionMenu -q -ni fileTypePopList`;
  586.         $typeList = `optionMenu -q -ils fileTypePopList`;
  587.         for ($index = 0; $index < $numTypes; $index++) {
  588.             $qFileType = `menuItem -q -l $typeList[$index]`;
  589.             if ($qFileType == $newType) {
  590.                 optionMenu -e -select ($index+1) fileTypePopList;
  591.                 sv_newFileType;
  592.                 break;
  593.             }
  594.         }
  595.         if ($index == $numTypes) {
  596.             // Make it type any since the type is unknown.
  597.             optionMenu -e -select 1 fileTypePopList;
  598.             sv_newFileType;
  599.         }
  600.     }
  601.  
  602. }
  603.  
  604. global proc pv_viewImage( string $filename )
  605. {   
  606.     waitCursor -state on;
  607.     string $fcheckCmd = "fcheck \"" + $filename + "\" 2>&1";
  608.     string $fcheckReturn = `system( $fcheckCmd )`;
  609.     
  610.     if ( match( "Unknown image format", $fcheckReturn ) != "" )
  611.     {   
  612.         confirmDialog -button OK -db OK -message 
  613.             "Display of this type of image is not supported";
  614.     }
  615.     waitCursor -state off;
  616. }
  617.  
  618. global proc int pv_selectCmd ( )
  619. //
  620. //    Description:
  621. //        a single click was recieve so a selection is being performed.
  622. //        Update information appropriate to the select.
  623. //
  624. {
  625.     global int $gv_displayMode;
  626.     global string $gv_wsFinder;
  627.     global int $gv_browserMode;
  628.     
  629.     // Set the finder text to the selected item name.
  630.     string    $selectedItem[];
  631.     string    $currentItem;
  632.     string    $fileType;
  633.     int        $numTypes;
  634.     string    $typeList[];
  635.     string    $qFileType;
  636.     string    $workspaceList[];
  637.     int        $wsIndex;
  638.     string    $wsViewerForm;
  639.     string    $wsViewerName[];
  640.     string    $theWorkspace;
  641.     string    $fileTypeList[];
  642.     
  643.     $str = `workspace -q -fn`;    // Replacing -lfw with -fn. -rams
  644.     $workspaceList[0] = $str;
  645.     
  646.     $wsViewerForm = `tabLayout -q -st workspaceTabs`;
  647.     $wsViewerName = `formLayout -q -ca $wsViewerForm`;
  648.  
  649.     $wsIndex = `tabLayout -q -sti workspaceTabs`;
  650.     $wsIndex = $wsIndex - 1;    // Make it 0 based for WS index.
  651.     
  652.     $theWorkspace = $workspaceList[$wsIndex];
  653.     
  654.     // Get the selected Item.
  655.     switch ($gv_displayMode) {
  656.     case    0        :    // Large Icon View
  657.     case    1        :    // Small Icon View
  658.     case    3        :    // Setup View
  659.     case    10        :    // Text (default) View
  660.     default            :
  661.         $selectedItem = `projFileViewer -q -si $wsViewerName[0]`;
  662.         break;
  663.     }
  664.  
  665.     // Now make the new workspace active.
  666.     //    workspace -act $theWorkspace;
  667.  
  668.     $currentItem = `workspace -q -dir $theWorkspace`;
  669.     
  670.     if (match("/$", $currentItem) != "/" && match("^/", $selectedItem[0]) != "/") {
  671.         $currentItem = $currentItem + "/" + $selectedItem[0];
  672.     } else {
  673.         $currentItem = $currentItem + $selectedItem[0];
  674.     }
  675.  
  676.     finder -e -fp $currentItem $gv_wsFinder;
  677.     
  678.     $fileTypeList = `file -q -typ $currentItem`;
  679.     int $numTrans = size($fileTypeList);
  680.     int $index;
  681.     if ($numTrans > 0) {
  682.         for ($index = 0; $index < $numTrans; $index++) {
  683.             switch ($gv_browserMode) {
  684.             case    0        :    // Read mode.
  685.             case    4        :
  686.                 if (`translator -q -rs $fileTypeList[$index]`) {
  687.                     $fileType = $fileTypeList[$index];
  688.                     $index = $numTrans;
  689.                 }
  690.                 break;
  691.             case    1        :    // Write mode.
  692.             case    2        :
  693.                 if (`translator -q -ws $fileTypeList[$index]`) {
  694.                     $fileType = $fileTypeList[$index];
  695.                     $index = $numTrans;
  696.                 }
  697.                 break;
  698.             }
  699.         }
  700.     } else {
  701.         $fileType = "Best Guess";
  702.     }
  703.  
  704.     // A file was selected so indicate the type.
  705.     pv_setMenuFileType($fileType, 0);
  706.  
  707.     //    Enable/disable the view image button based 
  708.     //    on the selected type
  709.     //
  710.     string $cmd = "pv_viewImage \"" + $currentItem + "\"";
  711.     button -e
  712.         -command $cmd
  713.         -enable ($fileType == "image") pv_viewImageButton;
  714.  
  715.     if (`about -evalVersion`)
  716.     {
  717.         // The evaluation version of Maya cannot use the system
  718.         // command so it cannot play sounds.  Just make sure that
  719.         // $fileType != audio so it will not try.
  720.         //
  721.         if ($fileType == "audio")
  722.         {
  723.             // Make a change that will invalidate the test below but
  724.             // (hopefully) not confuse any humans who may be looking
  725.             // at the value.
  726.             //
  727.             $fileType = "AUDIO";
  728.         }
  729.     }
  730.     
  731.     //    Enable/disable the play sound button based 
  732.     //    on the selected type
  733.     //
  734.     string $cmd = ( "waitCursor -state on; " );
  735.     $cmd = $cmd + ( "system( \"soundplayer " + $currentItem + "\"); " );
  736.     $cmd = $cmd + ( "waitCursor -state off; " );
  737.     button -e
  738.         -command $cmd
  739.         -enable ($fileType == "audio") pv_playSoundButton;
  740.     
  741.     return 1;
  742. }
  743.  
  744. global proc pv_selectTab ( )
  745. //
  746. //    Description:
  747. //        This callback in invoked when a viewer tab is selected.
  748. //
  749. {
  750.     global int $gv_displayMode;
  751.     string    $selectedItem[];
  752.     int        $numSelected;
  753.     string    $wsViewerForm;
  754.     string    $wsViewerName[];
  755.     int        $index;
  756.     
  757.     pv_redrawView;    // refresh the view.
  758.     
  759.     $wsViewerForm = `tabLayout -q -st workspaceTabs`;
  760.     $wsViewerName = `formLayout -q -ca $wsViewerForm`;
  761.  
  762.     switch ($gv_displayMode) {
  763.     case    0        :    // Large Icon View
  764.     case    1        :    // Small Icon View
  765.     case    3        :    // Setup View
  766.     case    10        :    // Text (default) View
  767.     default            :
  768.         $numSelected = `projFileViewer -q -nsi $wsViewerName[0]`;
  769.         $selectedItem = `projFileViewer -q -si $wsViewerName[0]`;
  770.         for ($index = 0; $index < $numSelected; $index++) {
  771.           projFileViewer -e -di $selectedItem[$index] $wsViewerName[0];
  772.         }
  773.         break;
  774.     }
  775.  
  776. }
  777.  
  778. global proc int pv_goDirectory (string $dirPath)
  779. //
  780. //    Description:
  781. //        Change the workspace directory to the given path
  782. //
  783. {
  784.     if ($dirPath == "") {
  785.         error ("Invalid directory path specified");
  786.         return 0;
  787.     } else {
  788.         workspace -dir $dirPath;
  789.         pv_redrawView;
  790.         return 1;
  791.     }
  792. }
  793.  
  794. global proc int pv_goCurrentProject ()
  795. //
  796. //    Description:
  797. //        return back to the root directory for this workspace.
  798. //
  799. {
  800.     workspace -dir `workspace -q -rd`;
  801.     pv_redrawView;
  802.     
  803.     return 1;
  804. }
  805.  
  806.  
  807. proc int pv_projViewer (int $mode, string $theParent, int $wsIndex, string $wsPath )
  808. //
  809. //    Description:
  810. //        Common functionality for text/icon views.
  811. //
  812. {
  813.     string        $argList; 
  814.     string        $wsFullName;
  815.     string        $viewerName = ("wsIconViewer"+$wsIndex);
  816.     string        $oldViewerName[];
  817.     string        $callBacks[];
  818.     string        $sortByMode;
  819.     global int    $gv_displayHiddenMode;
  820.     
  821.     
  822.     $wsFullName = `workspace -q -fn $wsPath`;
  823.     $argList = ("\""+ $wsFullName+"\" "+$wsIndex);
  824.      $callBacks[0] = ("pv_selectCmd");
  825.      $callBacks[1] = ("pv_doubleClickAction 1");
  826.  
  827.     if (!`optionVar -ex fileBrowserSortMode`) {
  828.         optionVar -sv fileBrowserSortMode "name";
  829.     }
  830.     $sortByMode = `optionVar -q fileBrowserSortMode`;
  831.  
  832.      setParent $theParent;
  833.     if (!`projFileViewer -ex $viewerName`) {
  834.         $oldViewerName = `formLayout -q -ca $theParent`;
  835.         if (size($oldViewerName) > 0) deleteUI $oldViewerName[0];
  836.         
  837.         projFileViewer -ws $wsFullName -dm $mode
  838.                 -sc $callBacks[0] 
  839.                 -dcc $callBacks[1] 
  840.                 -sortBy $sortByMode
  841.                 -dh $gv_displayHiddenMode
  842.                 $viewerName;
  843.         formLayout -e -af $viewerName "left" 0 -af $viewerName "right" 0
  844.                         -af $viewerName "top" 0 -af $viewerName "bottom" 0
  845.                         $theParent;
  846.     } else {
  847.         if ($mode != `projFileViewer -q -dm $viewerName`) {
  848.             projFileViewer -e -dm $mode $viewerName;    // Could be layout change.
  849.         }
  850.  
  851.         if ($sortByMode != `projFileViewer -q -sortBy $viewerName`) {
  852.             projFileViewer -e -sortBy $sortByMode $viewerName;
  853.         }
  854.  
  855.         if ($gv_displayHiddenMode != `projFileViewer -q -dh $viewerName`) {
  856.             projFileViewer -e -dh $gv_displayHiddenMode $viewerName;
  857.         }
  858.     }
  859.     
  860.     projFileViewer -e -fr $viewerName;
  861.     
  862.     return 1;
  863. }
  864.  
  865. global proc int pv_projIconViewer ( string $theParent, int $wsIndex, string $wsPath )
  866. //
  867. //    Description:
  868. //        setup all the callbacks and create the icon viewer.
  869. //
  870. {
  871.     global int $gv_displayMode;
  872.     
  873.     $gv_displayMode = 0;
  874.     optionVar -iv fileBrowserDisplayMode $gv_displayMode;
  875.     
  876.     return pv_projViewer(1, $theParent, $wsIndex, $wsPath);
  877. }
  878.  
  879. global proc int pv_projSmallIconViewer ( string $theParent, int $wsIndex, string $wsPath )
  880. //
  881. //    Description:
  882. //        setup all the callbacks and create the icon viewer.
  883. //
  884. {
  885.     global int $gv_displayMode;
  886.     
  887.     $gv_displayMode = 1;
  888.     optionVar -iv fileBrowserDisplayMode $gv_displayMode;
  889.     
  890.     return pv_projViewer(2, $theParent, $wsIndex, $wsPath);
  891. }
  892.  
  893. global proc int pv_projTextViewer ( string $theParent, int $wsIndex, string $wsPath )
  894. //
  895. //    Description:
  896. //        setup all the callbacks and create the icon viewer.
  897. //
  898. {
  899.     global int $gv_displayMode;
  900.     
  901.     $gv_displayMode = 10;
  902.     optionVar -iv fileBrowserDisplayMode $gv_displayMode;
  903.     
  904.     return pv_projViewer(0, $theParent, $wsIndex, $wsPath);
  905. }
  906.  
  907.  
  908. global proc int pv_resetWorkspace ( )
  909. //
  910. //    Description:
  911. //        The window is already created but for some reason our workspaces have
  912. //        changed. Update the information.
  913. //
  914. {
  915.     int $index;
  916.     int $numWS;
  917.     string $workspaces[];
  918.     string $workspacePaths[];
  919.     string $allTabs[];
  920.     int $viewMode;
  921.     string $wsViewerForm;
  922.     string $viewerName[];
  923.         
  924.     // Replacing -lw & -lfw with -sn & -fn. -rams
  925.     //
  926.     $str = `workspace -q -sn`;                // Get workspace short names.
  927.     $workspaces[0] = $str;
  928.     $str = `workspace -q -fn`;                // Get workspace full names.
  929.     $workspacePaths[0] = $str;
  930.     
  931.     $numWS = size($workspaces);
  932.         
  933.     $allTabs = `tabLayout -q -ca workspaceTabs`;
  934.  
  935.     for ($index = 0; $index < $numWS; $index++) {
  936.         $wsViewerForm = "wsViewerForm"+$index;
  937.  
  938.         if (!`formLayout -ex $wsViewerForm`) {
  939.             setParent workspaceTabs;
  940.             formLayout $wsViewerForm;
  941.         } else {
  942.             // Clear out the old information.
  943.             $viewerName = `formLayout -q -ca $wsViewerForm`;
  944.             if (size($viewerName) > 0) deleteUI $viewerName[0];
  945.         }
  946.         tabLayout -e -tl $wsViewerForm $workspaces[$index] workspaceTabs;
  947.     }
  948.     
  949.  
  950.     // Remove unused tabs.
  951.  
  952.     if (size($allTabs) > ($numWS)) {
  953.         for ($index = $numWS; $index < size($allTabs); $index++) {
  954.             deleteUI $allTabs[$index];    // Remove tab.
  955.         }
  956.     }
  957.     
  958.     pv_redrawView();
  959.  
  960.     return 1;
  961. }
  962.  
  963.  
  964. proc buildControlArea ( string $parent )
  965. {
  966.     global int $gv_browserMode;
  967.     global string $gv_wsFinder = "wsFinder0";
  968.  
  969.     setParent $parent;
  970.  
  971.     string $workspacePath = `workspace -q -fn`;
  972.     finder -adr false -c ("pv_doubleClickAction 1")
  973.         -fp $workspacePath $gv_wsFinder;
  974.  
  975.     button -align "center"  actionOK;
  976.  
  977.     // Create buttons to see image files and hear sound files
  978.  
  979.     button -l "See Image" -align "center"
  980.         -enable false
  981.         -c "" pv_viewImageButton;
  982.  
  983.     button -l "Hear Sound" -align "center"
  984.         -enable false
  985.         -c "" pv_playSoundButton;
  986.  
  987.     button -l "Cancel" -align "center"
  988.         -c ("{global string $gv_operationMode;"
  989.                 + "$gv_operationMode = \"\";"
  990.                 + "window -e -vis false projectViewerWindow;}") saveFileCancel;
  991.  
  992.     formLayout -e 
  993.         -af $gv_wsFinder "top" 0
  994.         -af $gv_wsFinder "left" 0
  995.         -af $gv_wsFinder "right" 0
  996.         -ac $gv_wsFinder "bottom" 0 actionOK
  997.  
  998.         -an actionOK "top" 
  999.         -af actionOK "left" 5
  1000.         -ap actionOK "right" 3 25 
  1001.         -af actionOK "bottom" 5
  1002.  
  1003.         -an pv_viewImageButton "top"
  1004.         -ap pv_viewImageButton "left" 2 25
  1005.         -ap pv_viewImageButton "right" 3 50
  1006.         -af pv_viewImageButton "bottom" 5
  1007.  
  1008.         -an pv_playSoundButton "top"
  1009.         -ap pv_playSoundButton "left" 2 50
  1010.         -ap pv_playSoundButton "right" 3 75 
  1011.         -af pv_playSoundButton "bottom" 5
  1012.  
  1013.         -an saveFileCancel "top"
  1014.         -ap saveFileCancel "left" 2 75
  1015.         -af saveFileCancel "right" 5
  1016.         -af saveFileCancel "bottom" 5
  1017.         controlArea;
  1018.  
  1019. }
  1020.  
  1021. // Pretty useless now, but maybe we'll expand
  1022. // the image translators...
  1023. proc string[] getImageTranslators()
  1024. {
  1025.     string $translators[];
  1026.     string $retArray[];
  1027.     int $count, $i, $j = 0;
  1028.  
  1029.     $translators = `translator -q -l`;
  1030.     $count = size( $translators );
  1031.  
  1032.     for ( $i = 0; $i < $count; $i++ )
  1033.     {
  1034.         if ( $translators[$i] == "image" )
  1035.         {
  1036.             $retArray[$j] = $translators[$i];
  1037.             $j++;
  1038.         }
  1039.     }
  1040.  
  1041.     return $retArray;
  1042. }
  1043.  
  1044. proc buildFileTypeMenu( int $mode, string $type )
  1045. {
  1046.     string    $fileTypes[];
  1047.     int        $count;
  1048.     int        $index;
  1049.  
  1050.     // Directory browser
  1051.     if ( $mode == 4 )
  1052.     {
  1053.         menuItem -l "directory" "DirectoryTypeMenu";
  1054.         return;
  1055.     }
  1056.  
  1057.     if ( $type == "image" && $mode != 0 )
  1058.     {
  1059.         menuItem -l "Maya IFF (iff)" iffTypeMenu;
  1060.         menuItem -l "Alias PIX (als)" aliasPIXTypeMenu;
  1061.         menuItem -l "Cineon (cin)" cineonTypeMenu;
  1062.         menuItem -l "EPS (eps)" epsTypeMenu;
  1063.         menuItem -l "GIF (gif)" gifTypeMenu;
  1064.         menuItem -l "JPEG (jpg)" jpegTypeMenu;
  1065.         menuItem -l "Quantel (yuv)" quantelTypeMenu;
  1066.         menuItem -l "RLA (rla)" rlaTypeMenu;
  1067.         menuItem -l "SGI (sgi)" sgiTypeMenu;
  1068.         menuItem -l "SoftImage (pic)" softImageTypeMenu;
  1069.         menuItem -l "Targa (tga)" targaTypeMenu;
  1070.         menuItem -l "Tiff (tif)" tiffTypeMenu;
  1071.         menuItem -l "Windows Bitmap (bmp)" bitmapTypeMenu;
  1072.         return;
  1073.     }
  1074.  
  1075.     if ( $type == "map" && $mode != 0 )
  1076.     {
  1077.         menuItem -l "From Tool Settings" ToolSettingsTypeMenu;
  1078.         return;
  1079.     }
  1080.  
  1081.     if ( $type == "mel" )
  1082.     {
  1083.         menuItem -l "mel" melfileTypeMenu;
  1084.         return;
  1085.     }
  1086.  
  1087.     // If iff is specified, we'll guess that that's the only
  1088.     // type supported (otherwise "image" should have been passed
  1089.     // as the type)
  1090.     if ( $type == "iff" )
  1091.     {
  1092.         menuItem -l "iff" ifffileTypeMenu;
  1093.         return;
  1094.     }
  1095.  
  1096.     if ( $type == "image" || $type == "map" )
  1097.     {
  1098.         $fileTypes = getImageTranslators();
  1099.         $count = size( $fileTypes );
  1100.         for ( $index = 0; $index < $count; $index ++ )
  1101.         {
  1102.             menuItem -l $fileTypes[$index] 
  1103.                 ($fileTypes[$index]+"fileTypeMenu");
  1104.         }
  1105.         return;
  1106.     }
  1107.         
  1108.     $fileTypes = `translator -q -l`;
  1109.     $count = size($fileTypes);
  1110.     for ($index = 0; $index < $count; $index++)
  1111.     {
  1112.         switch ($mode)
  1113.         {
  1114.             case    0        :    // Read mode.
  1115.                 if (`translator -q -rs $fileTypes[$index]`) {
  1116.                     menuItem -l $fileTypes[$index] 
  1117.                         ($fileTypes[$index]+"fileTypeMenu");
  1118.                 }
  1119.                 break;
  1120.             case    1        :    // Write mode.
  1121.                 if (`translator -q -ws $fileTypes[$index]`) {
  1122.                     menuItem -l $fileTypes[$index] 
  1123.                         ($fileTypes[$index]+"fileTypeMenu");
  1124.                 }
  1125.                 break;
  1126.             case    2        :
  1127.                 if (`translator -q -ws $fileTypes[$index]`) {
  1128.                     switch ($fileTypes[$index]) {
  1129.                         // only 2 possible choices.
  1130.                         case    "mayaAscii"        :
  1131.                         case    "mayaPLE"        :                            
  1132.                         case    "mayaBinary"    :
  1133.                             menuItem -l $fileTypes[$index] 
  1134.                                 ($fileTypes[$index]+"fileTypeMenu");
  1135.                             break;
  1136.                     }
  1137.                 }
  1138.                 break;
  1139.         }
  1140.     }
  1141. }
  1142.  
  1143. global proc int launchViewer ()
  1144. {
  1145.     string $action = "";
  1146.     string $type = "";
  1147.     return launchViewerNew ( $action, $type );
  1148. }
  1149.  
  1150. global proc int launchViewerNew ( string $action, string $type )
  1151. //
  1152. //    Description:
  1153. //        The viewer for the file dialog.
  1154. //
  1155. {
  1156.     global int $gv_browserMode;
  1157.  
  1158.     string $fileTypes[];
  1159.     int $index;
  1160.     int $numTypes;
  1161.     string $filePath;
  1162.     int $numWS;
  1163.     string $workspaces[];
  1164.     string $workspacePaths[];
  1165.     string $localWSName;
  1166.     string $wsForm;
  1167.     string $wsViewer;
  1168.     string $wsViewerForm;
  1169.     string $fileTypeLayout;
  1170.     string $fileTypeLabel, $fileTypeFeedback, $fileTypeOptionMenu;
  1171.  
  1172.     // Replacing -lw & -lfw with -sn & -fn. -rams
  1173.     //
  1174.     $str = `workspace -q -sn`;                // Get workspace short names.
  1175.     $workspaces[0] = $str;
  1176.     $str = `workspace -q -fn`;                // Get workspace full names.
  1177.     $workspacePaths[0] = $str;
  1178.  
  1179.     $localWSName = $workspaces[0];            // There is always 1 workspace.
  1180.     
  1181.     $numWS = size($workspaces);
  1182.         
  1183.     window -title "Save As"
  1184.         -menuBar true
  1185.         -rtf false -wh 450 510 
  1186.         -retain
  1187.         projectViewerWindow;
  1188.  
  1189.         sv_Menu("projectViewerWindow");
  1190.  
  1191.         // Setup the local workspace.
  1192.         //
  1193.  
  1194.         // Use the workspace index to name the objects.
  1195.         $wsViewer = "wsIconViewer0";
  1196.         $wsForm = "wsForm0";
  1197.         $wsViewerForm = "wsViewerForm0";
  1198.  
  1199.         formLayout $wsForm;
  1200.             
  1201.             //    Use a form layout instead of a row layout. Does a
  1202.             //    better job of resizing correctly. Also helps fix the
  1203.             //    Linux/Motif 2.1 problem with the option menu sometimes
  1204.             //    shrinking to an unusable size.
  1205.             //    -bwk 29.Nov.01
  1206.             //
  1207.             $fileTypeLayout = `formLayout`;
  1208.  
  1209.             $fileTypeLabel = `text -label "File Type:" fileTypeLabel`;
  1210.             $fileTypeFeedback = `text -label "" fileTypeFeedback`;
  1211.  
  1212.             if ($gv_browserMode == 0 || $gv_browserMode == 4) {
  1213.                  $fileTypeOptionMenu = `optionMenu -label "Read As:"
  1214.                     -changeCommand "sv_newFileType"
  1215.                     fileTypePopList`;
  1216.                 if ( $gv_browserMode != 4 ) {
  1217.                      menuItem -label "Best Guess" "AnyfileTypeMenu";
  1218.                 }
  1219.             } else {
  1220.                  $fileTypeOptionMenu = `optionMenu -label "Write As:"
  1221.                     -changeCommand "sv_newFileType"
  1222.                     fileTypePopList`;
  1223.             }
  1224.  
  1225.             formLayout -edit
  1226.                 -attachForm    $fileTypeLabel      "top"    0
  1227.                 -attachForm    $fileTypeLabel      "left"   0
  1228.                 -attachForm    $fileTypeLabel      "bottom" 0
  1229.                 -attachNone    $fileTypeLabel      "right"
  1230.  
  1231.                 -attachForm    $fileTypeFeedback   "top"    0
  1232.                 -attachControl $fileTypeFeedback   "left"   0 $fileTypeLabel
  1233.                 -attachForm    $fileTypeFeedback   "bottom" 0
  1234.                 -attachNone    $fileTypeFeedback   "right"
  1235.  
  1236.                 -attachForm    $fileTypeOptionMenu "top"    0
  1237.                 -attachNone    $fileTypeOptionMenu "left"
  1238.                 -attachForm    $fileTypeOptionMenu "bottom" 0
  1239.                 -attachForm    $fileTypeOptionMenu "right"  0
  1240.                 $fileTypeLayout;
  1241.                 
  1242.             buildFileTypeMenu( $gv_browserMode, $type);
  1243.  
  1244.         setParent $wsForm;
  1245.             // For centering the bottom buttons
  1246.             int $numDivisions = 100;
  1247.             formLayout -nd $numDivisions controlArea;
  1248.  
  1249.         setParent $wsForm;
  1250.  
  1251.             // Create the viewers for the various workspaces.
  1252.             //
  1253.             tabLayout -tv false -cc "pv_selectTab" workspaceTabs;
  1254.                 for ($index = 0; $index < $numWS; $index++) {
  1255.                     $wsViewerForm = "wsViewerForm"+$index;
  1256.  
  1257.                     formLayout $wsViewerForm;
  1258.                     // The layout control is supplied when drawn.
  1259.  
  1260.                     tabLayout -e -tl $wsViewerForm $workspaces[$index] workspaceTabs;
  1261.                     
  1262.                     setParent workspaceTabs;
  1263.                 }
  1264.                     
  1265.         setParent $wsForm;
  1266.             formLayout -edit 
  1267.                 -attachForm    $fileTypeLayout "top" 0
  1268.                 -attachForm    $fileTypeLayout "left" 5
  1269.                 -attachNone    $fileTypeLayout "bottom"
  1270.                 -attachForm    $fileTypeLayout "right" 5
  1271.  
  1272.                 -attachControl workspaceTabs   "top"    5 $fileTypeLayout
  1273.                 -attachForm    workspaceTabs   "right"  5
  1274.                 -attachForm    workspaceTabs   "left"   5
  1275.                 -attachControl workspaceTabs   "bottom" 5 controlArea
  1276.                 
  1277.                 -attachNone    controlArea     "top"
  1278.                 -attachForm    controlArea     "left"   5
  1279.                 -attachForm    controlArea     "right"  5
  1280.                 -attachForm    controlArea     "bottom" 5
  1281.                 $wsForm;
  1282.  
  1283.     return 1;
  1284. }
  1285.  
  1286. global proc int fileBrowser ( string $callBack, string $action, string $type,
  1287.                               int $mode)
  1288.     //
  1289.     //    Description:
  1290.     //        This is the main for the projectViewer.
  1291.     //
  1292.     //    Parameters:
  1293.     //        $callBack        - the global callback to be invoked when the action
  1294.     //                            button is pressed.
  1295.     //        $action            - the title for the action button.
  1296.     //        $type            - the file type to be highlited in the type
  1297.     //                            selection menu.
  1298.     //        $mode            - 0 for read, 1 for write.
  1299.     //                            2 for write-segmented (no paths)
  1300.     //                            4 give directories meaning on action.
  1301.     //
  1302. {
  1303.     global int $gv_displayMode;
  1304.     global int $gv_displayHiddenMode;
  1305.     global string $gv_CallBackCommand;
  1306.     global int $gv_browserMode;
  1307.     global string $gv_operationMode;
  1308.     global string $gDefaultFileBrowserDir;
  1309.         
  1310.     string $wsNames[];
  1311.  
  1312.     // Check for short names
  1313.     // These are being phased out of the UI, but we'll
  1314.     // strip out the 100 in case there are scripts around
  1315.     // which use it still.
  1316.     int $catch_oldShortNames = int($mode/100);
  1317.     $mode = $mode - 100 * $catch_oldShortNames;
  1318.  
  1319.     $gv_browserMode = $mode;
  1320.  
  1321.     if (`about -evalVersion` && $mode != 0) {
  1322.         if ($type == "mayaBinary" || $type == "mayaAscii") {
  1323.             // switch the file type to ple since ascii and binary are not
  1324.             // supported in the personal learning edition
  1325.         //
  1326.             $type = "mayaPLE";
  1327.         }
  1328.     }
  1329.  
  1330.     // Override the default directory if global variable is set
  1331.     if(size($gDefaultFileBrowserDir) > 0) {
  1332.         workspace -dir $gDefaultFileBrowserDir;
  1333.     }
  1334.     
  1335.     if (`about -nt` || `about -mac`) {
  1336.         string $workspace = `workspace -q -fn`;
  1337.         // note globals do NOT get set
  1338.         fileBrowserDialog -fc $callBack -m $mode -ft $type
  1339.             -an $action -om $gv_operationMode -in $workspace;
  1340.         // previous call blocks
  1341.         $gv_operationMode="";
  1342.         return 1;
  1343.     }
  1344.  
  1345.     if (`window -exists projectViewerWindow`) {
  1346.  
  1347.         // Hide the window to do cosmetics.
  1348.         window -e -vis false projectViewerWindow;
  1349.  
  1350.         if (`formLayout -ex WSeditForm`) {
  1351.             menuItem -e -cb false viewWorkspaceEdit;
  1352.             deleteUI WSeditForm;
  1353.         }
  1354.             
  1355.         //
  1356.         // Rebuild the popdown list because the translator list might have
  1357.         // changed.
  1358.         //
  1359.         string $typeList[] = `optionMenu -q -ill fileTypePopList`;
  1360.         int $index;
  1361.         int $count;
  1362.             
  1363.         //    Before deleting all the menu items create a temporary
  1364.         //    dummy menu item. This fixes the problem on Linux/Motif 2.1
  1365.         //    where the option menu sometimes shrinks to an unusable
  1366.         //    size. The option menu widget is not very good at determining
  1367.         //    it's size when it has no menu items. Motif 2.1 seems
  1368.         //    to have more difficulty with this than Motif 1.2.
  1369.         //
  1370.         //    Note also that an arbitrary label string is required, 
  1371.         //    otherwise Motif 2.1 will still have trouble figuring out
  1372.         //    the    option menu's proper size.
  1373.         //
  1374.         string $dummyItem = `menuItem -parent fileTypePopList -label "Bogus"`;
  1375.  
  1376.         //    Delete all the old menu items in the popup menu.
  1377.         //
  1378.         $count = size($typeList);
  1379.         for ($index = 0; $index < $count; $index++) {
  1380.             deleteUI -menuItem $typeList[$index];
  1381.         }
  1382.  
  1383.         setParent -menu fileTypePopList;
  1384.  
  1385.         if ($gv_browserMode == 0 || $gv_browserMode == 4) {
  1386.             optionMenu -edit -label "Read As:" fileTypePopList;
  1387.             if ( $gv_browserMode != 4 )
  1388.                 menuItem -label "Best Guess" "AnyfileTypeMenu";
  1389.         } else {
  1390.             optionMenu -edit -label "Write As:" fileTypePopList;
  1391.         }
  1392.  
  1393.         //    Set the correct label based on the file operation.
  1394.         //
  1395.         buildFileTypeMenu( $gv_browserMode, $type );
  1396.         
  1397.         //    Delete the temporary menu item now that the option menu
  1398.         //    contains all the new file type items.
  1399.         //
  1400.         deleteUI -menuItem $dummyItem;
  1401.  
  1402.         optionMenu -e -select 1 fileTypePopList;
  1403.         if (`window -q -i projectViewerWindow`) {    // If window iconic.
  1404.             window -e -i false projectViewerWindow;    // restore window.
  1405.         } 
  1406.         
  1407.     } else {
  1408.         if (`optionVar -ex fileBrowserDisplayMode`) {
  1409.             $gv_displayMode = `optionVar -q fileBrowserDisplayMode`;
  1410.         } else {
  1411. //            $gv_displayMode = 0;
  1412.             $gv_displayMode = 10;
  1413.         }
  1414.  
  1415.         if (`optionVar -ex fileBrowserDisplayHiddenMode`) {
  1416.             $gv_displayHiddenMode = `optionVar -q fileBrowserDisplayHiddenMode`;
  1417.         } else {
  1418.             $gv_displayHiddenMode = 0;
  1419.         }
  1420.  
  1421.         launchViewerNew ($action, $type);
  1422.         buildControlArea "controlArea";
  1423.     }
  1424.  
  1425.     $str = `workspace -q -sn`;    // Replacing -lw with -sn. -rams
  1426.     $wsNames[0] = $str;
  1427.  
  1428.     window -e 
  1429.         -t ($action + " ("+$wsNames[0]+")") 
  1430.         -iconName $action projectViewerWindow;
  1431.  
  1432.     // Special case:  when the mode is "save as", the action button
  1433.     // should say "save"
  1434.     //
  1435.     if ( $action == "Save As" ) $action = "Save";
  1436.  
  1437.  
  1438.     if ($gv_browserMode == 4) {
  1439.         button -e -l $action -align "center" -w 110
  1440.             -c ("pv_doubleClickAction 0") actionOK;
  1441.     } else {
  1442.         button -e -l $action -align "center" -w 110
  1443.             -c ("pv_doubleClickAction 1") actionOK;
  1444.     }
  1445.  
  1446.     if ($gv_operationMode == "") {
  1447.         // There is no options.
  1448.         menuItem -e -l "No Options" -c "" fileOptionsMenuItem; 
  1449.     } else {
  1450.         menuItem -e -l "Options..."
  1451.             -c ("{global string $gv_operationMode;"+
  1452.                 " window -e -vis false projectViewerWindow;"+
  1453.                 " fileOptions $gv_operationMode (\"projectViewer \"+$gv_operationMode);"+
  1454.                 " $gv_operationMode = \"\";}") fileOptionsMenuItem;
  1455.  
  1456.  
  1457.     }
  1458.  
  1459.     pv_setMenuFileType($type, 1);
  1460.     $gv_CallBackCommand = $callBack;
  1461.  
  1462.     pv_redrawView;
  1463.  
  1464.     showWindow projectViewerWindow;
  1465.  
  1466.     if (`saveImage -ex fo_saveIcon`) {
  1467.         saveImage -e -cv fo_saveIcon;        // Update with current view.
  1468.     }
  1469.     
  1470.     return 1;
  1471. }
  1472.